package com.zqwh.xtool.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.zqwh.xtool.R;

import java.util.Timer;
import java.util.TimerTask;

public class FinishActivity extends BaseActivity {
    private TextView tvFinish;
    private Timer timerOver;
    private int timerCount = 5;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_finish);
        setView();
        startOverTimer();
    }

    private void setView() {
        tvFinish = findViewById(R.id.tv_finish);
        tvFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (timerOver != null) {
                    timerOver.cancel();
                }
                finish();
            }
        });
    }

    private void startOverTimer() {
        timerOver = new Timer(true);
        timerOver.schedule(new TimerTask() {
            public void run() {
                timerCount --;
                if (timerCount == 0) {
                    finish();
                }
            }
        },1000, 1000);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timerOver != null) {
            timerOver.cancel();
            timerOver = null;
        }
    }
}
